<?xml version="1.0"?>
<yandex>
  <!-- config.xml引用的名字 -->
  <clickhouse_remote_servers>
    <!-- 分布式配置示例，即集群节点配置。集群有多个节点时直接拷贝此文件到所有集群中的节点即可 -->
    <{{ ck_cluster_name }}>
      {% for host in groups['clickhouse'] %}
      <shard>
        <internal_replication>true</internal_replication>
        <replica>
          <host>{{ hostvars[host].ansible_host }}</host>
          <port>{{ ck_tcp_port }}</port>
          <user>default</user>
          <password>{{ ck_default_password }}</password>
        </replica>
      </shard>
      {% endfor %}
    </{{ ck_cluster_name }}>
  </clickhouse_remote_servers>

  <!-- 使用集群的时候需要配置zookeeper，用于副本数据同步 -->
  <!-- 动态Keeper配置 -->
  <zookeeper-servers>
    {% for host in groups['clickhouse'] %}
    <node index="{{ loop.index }}">
      <host>{{ hostvars[host].ansible_host }}</host>
      <port>{{ ck_keeper_port | default(9181) }}</port>
    </node>
    {% endfor %}
  </zookeeper-servers>

  <!-- macros配置 -->
  <macros>
    <shard>{{ shard_id }}</shard>
    <!-- 每个节点使用自己的IP作为副本标识 -->
    <replica>{{ ansible_host }}</replica>
  </macros>

  <networks>
    <ip>::/0</ip>
  </networks>

  <!-- 会压缩30-100%的数据，节省磁盘空间 -->
  <clickhouse_compression>
    <case>
      <!-- 最小的part -->
      <min_part_size>10000000000</min_part_size>
      <!-- 整个表里最小的part -->
      <min_part_size_ratio>0.01</min_part_size_ratio>
      <!-- 压缩方式. -->
      <method>lz4</method>
    </case>
  </clickhouse_compression>
</yandex>
